package net.uhuijia.software.softwarerequest.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.uhuijia.utils.IticConst;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.uhuijia.appbase.service.CrudService;
import net.uhuijia.constants.DBConst;
import net.uhuijia.software.softwarerequest.persistence.dao.SoftwareRequestDao;
import net.uhuijia.software.softwarerequest.persistence.model.SoftwareRequest;
import net.uhuijia.software.softwarerequest.persistence.model.SoftwareRequestExample;
import net.uhuijia.software.softwarerequest.persistence.model.SoftwareRequestExample.Criteria;
import net.uhuijia.software.softwarerequest.service.SoftwareRequestService;
import net.uhuijia.user.usermall.persistence.model.UserMall;


@Service
@Transactional
public class SoftwareRequestServiceImpl
     extends CrudService<SoftwareRequestDao,SoftwareRequest,SoftwareRequestExample>
     implements  SoftwareRequestService {

	@Override
	public List<SoftwareRequest> listUserHistoryRequestAndPage(HttpServletRequest request, UserMall user) {
		SoftwareRequestExample example = new SoftwareRequestExample();
		IticConst.handlePageQueryDefault(request,example);
		example.setOrderByClause("CREATE_TIME DESC");
		Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andUserIdEqualTo(user.getId());
		List<SoftwareRequest> softwareRequests = this.list(example);
		return softwareRequests;
	}

	@Override
	public Integer countUserHistoryRequest(UserMall user) {
		SoftwareRequestExample example = new SoftwareRequestExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andUserIdEqualTo(user.getId());
		return mapper.countByExample(example);
	}
}